//
//  LKKeyValueStore.h
//  LKKeyValueStore
//
//  Created by LK-IOS on 2017/8/1.
//  Copyright © 2017年 LK-IOS. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface LKKeyValueItem : NSObject

@property (strong, nonatomic) NSString *itemId;
@property (strong, nonatomic) id itemObject;
@property (strong, nonatomic) NSDate *createdTime;

@end

@interface LKKeyValueStore : NSObject

//提供单利创建的方法
+(instancetype)sharedInstance;

+(instancetype)sharedInstanceWithdbName:(NSString *)dbName;


/**
 根据名字创建数据库

 @param dbName 名称
 @return 返回对象本身
 */
- (id)initDBWithName:(NSString *)dbName;

/**
 根据路径创建数据库
 @param dbPath 路径
 @return 返回对象本身
 */
- (id)initWithDBWithPath:(NSString *)dbPath;

/**
 根据表名称创建表

 @param tableName 表名称
 */
- (void)createTableWithName:(NSString *)tableName;

/**
 判断是不是存在表

 @param tableName 表名称
 @return 返回值
 */
- (BOOL)isTableExists:(NSString *)tableName;

/**
 清空表

 @param tableName 表名称
 */
- (void)clearTable:(NSString *)tableName;

- (void)close;

///************************ Put&Get methods *****************************************

/**
 根据ID存储一个对象

 @param object 存储的对象
 @param objectId ID名称
 @param tableName 表名称
 */
- (void)putObject:(id)object withId:(NSString *)objectId intoTable:(NSString *)tableName;

/**
 根据ID获取存储的对象

 @param objectId ID名成
 @param tableName 表名称
 @return 返回的对象
 */
- (id)getObjectById:(NSString *)objectId fromTable:(NSString *)tableName;

- (LKKeyValueItem *)getYTKKeyValueItemById:(NSString *)objectId fromTable:(NSString *)tableName;



/**
 根据ID存储一个字符串

 @param string 存储的字符串
 @param stringId ID名成
 @param tableName 表名称
 */
- (void)putString:(NSString *)string withId:(NSString *)stringId intoTable:(NSString *)tableName;


/**
 根据ID获取存储的字符串
 @param stringId ID名称
 @param tableName 表名称
 @return 返回的字符串
 */
- (NSString *)getStringById:(NSString *)stringId fromTable:(NSString *)tableName;


//存储数字及获取数字
- (void)putNumber:(NSNumber *)number withId:(NSString *)numberId intoTable:(NSString *)tableName;

- (NSNumber *)getNumberById:(NSString *)numberId fromTable:(NSString *)tableName;

//获取表中的全部数据
- (NSArray *)getAllItemsFromTable:(NSString *)tableName;

//删除
- (void)deleteObjectById:(NSString *)objectId fromTable:(NSString *)tableName;

- (void)deleteObjectsByIdArray:(NSArray *)objectIdArray fromTable:(NSString *)tableName;

- (void)deleteObjectsByIdPrefix:(NSString *)objectIdPrefix fromTable:(NSString *)tableName;


/**
 * ------------------------"  存入  " -----------------------
 */
// 存入单个模型
- (void)putModelObject:(id)object withId:(NSString *)objectId intoTable:(NSString *)tableName;

// 存入模型数组：一个Model一个Id
- (void)putModelObjectArray:(NSArray *)objectArray withIdArray:(NSArray *)objectIdArray intoTable:(NSString *)tableName;

// 存入模型数组：只用一个Id
- (void)putModelObjectArray:(NSArray *)objectArray intoTable:(NSString *)tableName;

/**
 * ------------------------"  取出  "-----------------------
 */
// 根据一个Id取出一个模型对象
- (id)getModelObjectById:(NSString *)objectId className:(Class)className fromTable:(NSString *)tableName;

// 根据一个表名取出一个数组模型对象
- (id)getModelArrayByclassName:(Class)className fromTable:(NSString *)tableName arrayCount:(int)arrayCount;

//
- (NSArray *)getItemsFromTable:(NSString *)tableName withRange:(NSRange)range;

// 表是否存在
- (BOOL)isExistTableWithName:(NSString *)tableName;


/**
 *  --------------------------"  删除  "----------------------
 */
//删除表
- (BOOL)deleteTable:(NSString *)tableName;

// 删除数据库
- (void)deleteDatabseWithDBName:(NSString *)DBName;

// 获取表库的路径
- (NSString *)getDBPath;



@end
